package dk.dlug.platform;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.StringTokenizer;

import javax.inject.Inject;
import javax.inject.Named;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import dk.dlug.platform.model.BoardModel;
import dk.dlug.platform.model.DefaultModel;

@Controller
public class HomeController {
	
	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
	
	public BoardModel getBoardModel() {
		return boardModel;
	}

	public void setBoardModel(BoardModel boardModel) {
		this.boardModel = boardModel;
	}

	public DefaultModel getDefaultModel() {
		return defaultModel;
	}

	public void setDefaultModel(DefaultModel defaultModel) {
		this.defaultModel = defaultModel;
	}

	public static Logger getLogger() {
		return logger;
	}

	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@Inject
	@Named("boardModel")
	BoardModel boardModel;

	@Inject
	@Named("defaultModel")
	private DefaultModel defaultModel;

	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String home(
			Locale locale, HashMap<String, Object> model
			,@RequestParam HashMap<String, Object> params
			) {
		logger.info("Welcome home! The client locale is {}.", locale);
		
		Date date = new Date();
		DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
		

		//model.put("list",(ArrayList)defaultModel.getList());
		model.put("list",boardModel.getList());
		
		defaultModel.test();
		int i=0;
		
		
		return "home";
	}
	
	@RequestMapping("/bb")
	public void printC(@RequestParam HashMap<String,Object> params) throws Exception{
		System.out.println("bb Call");
		
		String[] opes= {"+","-","*","/"};
		
		String value = (String)params.get("inputBox");
		ArrayList<String> valueArr =  new ArrayList<String>();
		String tempVal ="";
		int a,b;
		
		
		if(value.contains("+")){
			StringTokenizer st = new StringTokenizer(value,"+");
			a = Integer.parseInt(st.nextToken());
			b = Integer.parseInt(st.nextToken());
			
			System.out.println(a+b);
		}else if(value.contains("-")){
			StringTokenizer st = new StringTokenizer(value,"-");
			
			a = Integer.parseInt(st.nextToken());
			b = Integer.parseInt(st.nextToken());
			
			System.out.println(a-b);
		}else if(value.contains("*")){
			StringTokenizer st = new StringTokenizer(value,"*");
			
			a = Integer.parseInt(st.nextToken());
			b = Integer.parseInt(st.nextToken());
			
			System.out.println(a*b);
		}else{
			StringTokenizer st = new StringTokenizer(value,"/");
			
			a = Integer.parseInt(st.nextToken());
			b = Integer.parseInt(st.nextToken());
			
			System.out.println(a/b);
		}
		
		System.out.println(params);
		
	}
	
	
	
}
